﻿using System;
using System.Linq;
using System.Windows.Forms;
using Aga.Controls.Tree;
using MyLibrary.UI;
namespace Uniquer
{
    public partial class MainForm : Form
    {
        private TreeModel _treeViewModel;

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainFormLoad(object sender, EventArgs e)
        {
            _treeViewModel = new TreeModel();
            resultView.Model = _treeViewModel;
        }

        private void AnalyzeButtonClick(object sender, EventArgs e)
        {
            resultView.BeginUpdate();
            ((TreeModel)resultView.Model).Nodes.Clear();
            resultView.EndUpdate();
            
            // Get input path from Folder browser
            var paths = resultView.SelectedNodes
                .Select(selectedNode => selectedNode.Tag as FolderItem)
                .Select(folderItem => folderItem.ItemPath).ToList();

            // Do calculations here

            resultView.BeginUpdate();
            
            // Add root
            var node = new ResultNode("Results (" + paths.Count + ")");
            _treeViewModel.Nodes.Add(node);

            foreach (var child in paths.Select(t => new ResultNode(t)))
            {
                node.Nodes.Add(child);
            }

            resultView.EndUpdate();
        }
    }
}
